import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JPanel;

class Browser extends JPanel{

    // Front end

    private Image img;

    Browser(Image img){
        this.img = img;
        Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
        setPreferredSize(size);
        setMinimumSize(size);
        setMaximumSize(size);
        setSize(size);
        setLayout(null);
    }

    public void paintComponent(Graphics g){
        g.drawImage(img, 0, 0, null);
    }


    // Back end

    private static Login user;
    private static DBConnection connection;

    /**
     * Print Ticket use case.
     */
    public void printTicket(){

        if ( user.checkLoggedIn() ){

            // Retrieve users Bookings
            // Select tickets to print

            // Confirm selection

            // Retrieve customer card details.

            String cardOwner;
            int cardNumber;
            int securityCode;
            Date begin = new Date();
            Date expire = new Date();

            CardDetails cardDetails = new CardDetails( cardOwner, cardNumber, securityCode, begin, expire );

            while ( !cardDetails.chargeCard() ){ // Remember cancel option!
                /* Get new details
                cardOwner
                cardNumber
                securityCode
                begin
                expire
                */
                cardDetails.updateDetails( cardOwner, cardNumber, securityCode, begin, expire );

            }

            // Print tickets

        } else { // login
            // Prompt login.
            user.doIt();
            printTicket();
        }

    }
    /**
     * Write film review use case.
     */
    public void writeReview() {
        if ( user.checkLoggedIn() ){

            // Retrieve films in the last week.
            // Browse or select films.

            // Retrieve film reviews.
            // Browse or write reviews.

            // Check review content.
            // Submit content.

        } else { // login
            // Prompt login.
            user.doIt();
            printTicket();
        }
    }

}

class BrowserButton extends JButton{
    private Image img;
    BrowserButton(Image img){
        this.img = img;
        Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
        setPreferredSize(size);
        setMinimumSize(size);
        setMaximumSize(size);
        setSize(size);
        setLayout(null);
    }

    public void paintComponent(Graphics g){
        g.drawImage(img, 0, 0, null);
    }

}

